package com.cl.blog.web.manager;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import com.cl.blog.common.Const;
import com.cl.blog.common.Result;
import com.cl.blog.entity.BAdmin;
import com.cl.blog.service.BAdminService;
import com.cl.blog.util.JwtUtil;
import com.cl.blog.vo.LoginVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 付
 * @Date 2024-03-15 17:31
 * @Version 1.0
 * @description
 * @since 1.0
 */

@RestController
@RequestMapping("/admin")
public class AdminLoginController {

	@Resource
	BAdminService bAdminService;
	@Resource
	JwtUtil jwtUtil;

	@PostMapping("/login")
	public Result login(@Validated @RequestBody LoginVo loginVo){
		System.out.println("获取的登录对象----"+loginVo);
		Assert.notNull(loginVo,"抱歉，用户名和密码不能为空");

		BAdmin bAdmin = bAdminService.login(loginVo);

		String token = jwtUtil.generateToken(bAdmin.getId(), Const.GRADE_ADMIN);
		bAdmin.setIssuer(Const.GRADE_ADMIN);
		bAdmin.setToken(token);
		return Result.success(bAdmin);
	}


}
